import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpClient {
    private Socket socketClient=null;

    public TcpClient(String ip,int port) throws IOException {
        socketClient=new Socket(ip,port);

    }

    public void start(){

        Scanner sc=new Scanner(System.in);
        try(InputStream inputStream=socketClient.getInputStream();
            OutputStream outputStream=socketClient.getOutputStream()){
            PrintWriter writer=new PrintWriter(outputStream);
            Scanner scanner=new Scanner(inputStream);
            while(true){

                System.out.println("请输入你的需求");
                String request=sc.next();


                writer.println(request);

                writer.flush();

                String respond=scanner.next();

                System.out.println(respond);




            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }







    }


    public static void main(String[] args) throws IOException {
        TcpClient tcpClient=new TcpClient("127.0.0.1",9090);

        tcpClient.start();
    }

}
